﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XEvents.Library;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;

namespace XEvents.Library.Tester
{
    class Program
    {
        static void Main(string[] args)
        {
            TestRun tr = new TestRun();
            tr.BuildMetaData();
        }

        public class TestRun
        {
            public void BuildMetaData()
            {
                SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder();
                bldr.DataSource = "oshodb06";
                bldr.IntegratedSecurity = true;

                DateTime start = DateTime.Now;
                SqlServer svr = new SqlServer("oshodb06");
                DateTime end = DateTime.Now;
                TimeSpan ts = end-start;
                Debug.WriteLine("Loaded Data in "+ ts.Milliseconds + " milliseconds.");

                foreach (EventSession ses in svr.EventSessions)
                {
                    Debug.WriteLine("Session name = " + ses.Name);
                    Debug.WriteLine("   This session has " + ses.Targets.Count().ToString() + " targets");
                    foreach (EventSessionTarget st in ses.Targets)
                    {
                        Debug.WriteLine("       Name: " + st.Name + " has " + st.Options.Count + " options");
                    }
                    Debug.WriteLine("   This session has " + ses.Events.Count().ToString() + " events");
                    foreach (EventSessionEvent se in ses.Events)
                    {
                        Debug.WriteLine("       Name: " + se.Name + " has " + se.ActionString);
                    }
                    Debug.WriteLine("");
                    Debug.WriteLine(ses.GenerateCreateScript());

                }

                /*
                foreach (Event evt in svr.MetaData.Events)
                {
                    Debug.WriteLine("Event name = " + evt.Name);
                    Debug.WriteLine("   Channel = " + evt.Channel.ToString());
                    Debug.WriteLine("   Keyword = " + evt.Keyword.ToString());
                    Debug.WriteLine("   This Event has " + evt.Columns.Count().ToString() + " columns");
                    foreach (Column c in evt.Columns)
                    {
                        Debug.WriteLine("       Name: " + c.Name + " Description: " + c.Description + " Capabilities: " + c.Capabilities);
                    }
                }
                */

            }

        }
    }
}
